import logging
import os,time

class Mylogger:

    def __init__(self):
        self.logger = logging.getLogger(name='crmeb')
        self.logger.setLevel(logging.DEBUG)
        format = logging.Formatter('[%(asctime)s] [%(levelname)s] [%(filename)s] %(message)s')

        st = logging.StreamHandler()
        st.setFormatter(logging.DEBUG)
        st.setFormatter(format)

        file_name = time.strftime("%Y-%m-%d-%H-%M-%S")
        root_dir = os.path.dirname(os.path.dirname(__file__))

        logs = os.path.join(root_dir,"logs")
        print("logsxxxxxxxx",logs)
        if not os.path.exists(logs):
            os.mkdir(logs)
        logfile = os.path.join(logs,file_name)
        print("logfilexxxxxxxxx",logfile)

        fl = logging.FileHandler(filename=logfile+".log",mode='w',encoding='UTF-8')
        fl.setLevel(logging.DEBUG)
        fl.setFormatter(format)

        self.logger.addHandler(st)
        self.logger.addHandler(fl)

    def debug(self,message):
        self.logger.debug(message)

    def info(self,message):
        self.logger.info((message))

    def warning(self,message):
        self.logger.warning((message))


logger = Mylogger()
if __name__ == '__main__':
    m1 = Mylogger()
    m1.warning('开始发送接口')



